package com.sdry.web.controller.zc.quality;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.sdry.model.zc.ZcAccessoriesCriterionEntity;
import com.sdry.model.zc.ZcEvaluateCriterionEntity;
import com.sdry.model.zc.ZcGasCriterionEntity;
import com.sdry.model.zc.ZcJzSpotCheckCriterionEntity;
import com.sdry.model.zc.ZcLeakHuntingCriterionEntity;
import com.sdry.model.zc.ZcQueryCriteria;
import com.sdry.model.zc.ZcSilkCriterionEntity;
import com.sdry.service.zc.ZcCriterionService;
import com.sdry.utils.ResponseUtil;

/**
 * 
 * @ClassName:    ZcCriterionController   
 * @Description:  质检标准
 * @Author:       zc   
 * @CreateDate:   2018年9月21日 下午4:15:07   
 * @Version:      v1.0
 */
@Controller
@RequestMapping("criterion")
public class ZcCriterionController {

	@Resource
	private ZcCriterionService zcCriterionService;
	/**
	 * 进入质检标准的增删改查页面
	 * @return
	 */
	@RequestMapping("enterCriterionPage")
	public String enterCriterionPage(){
		return "/zc/quality/criterion";
	}
	/**
	 * 查找配件检验标准项
	 * @param request
	 * @param response
	 */
	@RequestMapping("selectAccessoriesCriterion")
	public void selectAccessoriesCriterion(HttpServletRequest request,HttpServletResponse response){
		try {
			ZcAccessoriesCriterionEntity zcAccessoriesCriterionEntity = zcCriterionService.selectAccessoriesCriterion();
			JSONObject json= JSONObject.fromObject(zcAccessoriesCriterionEntity);  
			if(zcAccessoriesCriterionEntity!=null){
				ResponseUtil.write(response, json);
			}else{
				ResponseUtil.write(response, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 保存配件检验标准项
	 * @param request
	 * @param response
	 * @param zcAccessoriesCriterionEntity
	 */
	@RequestMapping("insertAccessoriesCriterion")
	public void insertAccessoriesCriterion(HttpServletRequest request,HttpServletResponse response,ZcAccessoriesCriterionEntity zcAccessoriesCriterionEntity){
		try {
			Date date = new Date();
			zcAccessoriesCriterionEntity.setGreatTime(date);
			int affact = zcCriterionService.insertAccessoriesCriterion(zcAccessoriesCriterionEntity);
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改配件检验标准项
	 * @param request
	 * @param response
	 * @param zcAccessoriesCriterionEntity
	 */
	@RequestMapping("editAccessoriesCriterion")
	public void editAccessoriesCriterion(HttpServletRequest request,HttpServletResponse response,ZcAccessoriesCriterionEntity zcAccessoriesCriterionEntity){
		Date date = new Date();
		zcAccessoriesCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.editAccessoriesCriterion(zcAccessoriesCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查找检漏标准项
	 * @param request
	 * @param response
	 */
	@RequestMapping("selectLeakHuntingCriterion")
	public void selectLeakHuntingCriterion(HttpServletRequest request,HttpServletResponse response){
		ZcLeakHuntingCriterionEntity zcLeakHuntingCriterionEntity = zcCriterionService.selectLeakHuntingCriterion();
		JSONObject json= JSONObject.fromObject(zcLeakHuntingCriterionEntity);  
		try {
			if(zcLeakHuntingCriterionEntity!=null){
				ResponseUtil.write(response, json);
			}else{
				ResponseUtil.write(response, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 保存检漏标准项
	 * @param request
	 * @param response
	 * @param zcLeakHuntingCriterionEntity
	 */
	@RequestMapping("insertLeakHuntingCriterion")
	public void insertLeakHuntingCriterion(HttpServletRequest request,HttpServletResponse response,ZcLeakHuntingCriterionEntity zcLeakHuntingCriterionEntity){
		Date date = new Date();
		zcLeakHuntingCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.insertLeakHuntingCriterion(zcLeakHuntingCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改检漏标准项
	 * @param request
	 * @param response
	 * @param zcLeakHuntingCriterionEntity
	 */
	@RequestMapping("editLeakHuntingCriterion")
	public void editLeakHuntingCriterion(HttpServletRequest request,HttpServletResponse response,ZcLeakHuntingCriterionEntity zcLeakHuntingCriterionEntity){
		Date date = new Date();
		zcLeakHuntingCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.editLeakHuntingCriterion(zcLeakHuntingCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查找组件评价标准项
	 * @param request
	 * @param response
	 */
	@RequestMapping("selectEvaluateCriterion")
	public void selectEvaluateCriterion(HttpServletRequest request,HttpServletResponse response){
		ZcEvaluateCriterionEntity zcEvaluateCriterionEntity = zcCriterionService.selectEvaluateCriterion();
		JSONObject json= JSONObject.fromObject(zcEvaluateCriterionEntity);  
		try {
			if(zcEvaluateCriterionEntity!=null){
				ResponseUtil.write(response, json);
			}else{
				ResponseUtil.write(response, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 保存组件评价标准项
	 * @param request
	 * @param response
	 * @param zcEvaluateCriterionEntity
	 */
	@RequestMapping("insertEvaluateCriterion")
	public void insertEvaluateCriterion(HttpServletRequest request,HttpServletResponse response,ZcEvaluateCriterionEntity zcEvaluateCriterionEntity){
		Date date = new Date();
		zcEvaluateCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.insertEvaluateCriterion(zcEvaluateCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改组件评价标准项
	 * @param request
	 * @param response
	 * @param zcEvaluateCriterionEntity
	 */
	@RequestMapping("editEvaluateCriterion")
	public void editEvaluateCriterion(HttpServletRequest request,HttpServletResponse response,ZcEvaluateCriterionEntity zcEvaluateCriterionEntity){
		Date date = new Date();
		zcEvaluateCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.editEvaluateCriterion(zcEvaluateCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查找气密检测标准项
	 * @param request
	 * @param response
	 */
	@RequestMapping("selectGasCriterion")
	public void selectGasCriterion(HttpServletRequest request,HttpServletResponse response){
		ZcGasCriterionEntity zcGasCriterionEntity = zcCriterionService.selectGasCriterion();
		JSONObject json= JSONObject.fromObject(zcGasCriterionEntity);  
		try {
			if(zcGasCriterionEntity!=null){
				ResponseUtil.write(response, json);
			}else{
				ResponseUtil.write(response, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 保存气密检测标准项
	 * @param request
	 * @param response
	 * @param zcGasCriterionEntity
	 */
	@RequestMapping("insertGasCriterion")
	public void insertGasCriterion(HttpServletRequest request,HttpServletResponse response,ZcGasCriterionEntity zcGasCriterionEntity){
		Date date = new Date();
		zcGasCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.insertGasCriterion(zcGasCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改气密检测标准项
	 * @param request
	 * @param response
	 * @param zcGasCriterionEntity
	 */
	@RequestMapping("editGasCriterion")
	public void editGasCriterion(HttpServletRequest request,HttpServletResponse response,ZcGasCriterionEntity zcGasCriterionEntity){
		Date date = new Date();
		zcGasCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.editGasCriterion(zcGasCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查找膜丝标准项
	 * @param request
	 * @param response
	 */
	@RequestMapping("selectSilkCriterion")
	public void selectSilkCriterion(HttpServletRequest request,HttpServletResponse response){
		ZcSilkCriterionEntity zcSilkCriterionEntity = zcCriterionService.selectSilkCriterion();
		JSONObject json= JSONObject.fromObject(zcSilkCriterionEntity);  
		try {
			if(zcSilkCriterionEntity!=null){
				ResponseUtil.write(response, json);
			}else{
				ResponseUtil.write(response, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 保存膜丝标准项
	 * @param request
	 * @param response
	 * @param zcSilkCriterionEntity
	 */
	@RequestMapping("insertSilkCriterion")
	public void insertSilkCriterion(HttpServletRequest request,HttpServletResponse response,ZcSilkCriterionEntity zcSilkCriterionEntity){
		Date date = new Date();
		zcSilkCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.insertSilkCriterion(zcSilkCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改膜丝标准项
	 * @param request
	 * @param response
	 * @param zcSilkCriterionEntity
	 */
	@RequestMapping("editSilkCriterion")
	public void editSilkCriterion(HttpServletRequest request,HttpServletResponse response,ZcSilkCriterionEntity zcSilkCriterionEntity){
		Date date = new Date();
		zcSilkCriterionEntity.setGreatTime(date);
		int affact = zcCriterionService.editSilkCriterion(zcSilkCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查找浇铸抽检标准列表
	 * @param request
	 * @param response
	 */
	@RequestMapping("selectJzSpotCheckCriterionList")
	public void selectJzSpotCheckCriterionList(HttpServletRequest request,HttpServletResponse response,ZcQueryCriteria zcQueryCriteria){
		List<ZcJzSpotCheckCriterionEntity> selectJzSpotCheckCriterionList = zcCriterionService.selectJzSpotCheckCriterionList(zcQueryCriteria);
		int count = zcCriterionService.countJzSpotCheckCriterionList(zcQueryCriteria);
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		
		JSONArray jsonArray = JSONArray.fromObject(selectJzSpotCheckCriterionList, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);
		jsonObject.put("count", count);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 保存浇铸抽检标准
	 * @param request
	 * @param response
	 * @param zcJzSpotCheckCriterionEntity
	 */
	@RequestMapping("insertJzSpotCheckCriterion")
	public void insertJzSpotCheckCriterion(HttpServletRequest request,HttpServletResponse response,ZcJzSpotCheckCriterionEntity zcJzSpotCheckCriterionEntity){
		int affact = zcCriterionService.insertJzSpotCheckCriterion(zcJzSpotCheckCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 删除浇铸抽检标准
	 * @param request
	 * @param response
	 * @param idArr
	 */
	@RequestMapping("delJzSpotCheckCriterionArr")
	public void delJzSpotCheckCriterionArr(HttpServletRequest request, HttpServletResponse response,@RequestParam("idArr[]") String[] idArr){
		int affact = 0;
		for (String jzId : idArr) {
			long id = Long.parseLong(jzId);
			affact += zcCriterionService.delJzSpotCheckCriterionArr(id);
		}
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改浇铸抽检标准
	 * @param request
	 * @param response
	 * @param zcJzSpotCheckCriterionEntity
	 */
	@RequestMapping("editJzSpotCheckCriterion")
	public void editJzSpotCheckCriterion(HttpServletRequest request,HttpServletResponse response,ZcJzSpotCheckCriterionEntity zcJzSpotCheckCriterionEntity){
		int affact = zcCriterionService.editJzSpotCheckCriterion(zcJzSpotCheckCriterionEntity);
		try {
			ResponseUtil.write(response, affact);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
